$(function() {
	$(".showCloseChk").change(function() {
		var lis = $(this).parent().parent().children();
		if (lis.eq(4).css("display") == "inline") {
			lis.eq(4).css("display", "none");
			lis.eq(3).css("display", "inline");
		} else {
			lis.eq(4).css("display", "inline");
			lis.eq(3).css("display", "none");
		}
		var flag = true;
		$(".deletBtn").each(function() {
			if ($(this).css("display") == "none") {
				flag = false;
			}
		});
		$("#select_all_top").prop("checked", flag);
		$("#select_all_bot").prop("checked", flag);
	});
	$("#select_all_top").change(function() {
		select_all($(this).prop("checked"));
	});
	$("#select_all_bot").change(function() {
		select_all($(this).prop("checked"));
	});

	function select_all(isChecked) {
		if (isChecked) {
			$(".lookMess").css("display", "none");
			$(".deletBtn").css("display", "inline");
			$(".showCloseChk").prop("checked", true);
			$("#select_all_top").prop("checked", true);
			$("#select_all_bot").prop("checked", true);
		} else {
			$(".lookMess").css("display", "inline");
			$(".deletBtn").css("display", "none");
			$(".showCloseChk").prop("checked", false);
			$("#select_all_top").prop("checked", false);
			$("#select_all_bot").prop("checked", false);
		}
	}


	$('.dd_mar').each(function(index) {
		$(this).children().first().click(function() {
			var uid = $('.deleteA').eq(index).attr('href');
			window.open("space_redirectPersonalSpace?user.userid=" + uid);
		});
	});

	$(".deleteA").click(function() {
		deleteMessage($(this));
		return false;
	});

	$(".deleteSelectMails").click(function() {
		$('.user_list').each(function() {
			if ($(this).find('.showCloseChk').prop("checked")) {
				var de = $(this).find('.deleteA');
				deleteMessage(de);
			}
		});
		return false;
	});

	function deleteMessage(deleteA) {
		$.post("mailBoxAjax_deleteLuckById", {
			"luck.id" : deleteA.attr('luckid')
		}, function(data) {
			if (data != "true") {
				art.dialog.alert('发生未知错误！！！').time(2);
			} else {
				deleteA.parent().parent().remove();
			}
		});
	}

});
